slova = str(input()).lower()
num = ''
num_slov = {
    "zero": 0, "one": 1,
    "two": 2, "three": 3,
    "four": 4, "five": 5,
    "six": 6, "seven": 7,
    "eight": 8, "nine": 9
            }

if len(slova.split()) == 3:
    for i in slova.split():
        try:
            num += str(num_slov[i])
        except:
            print("Wrong input")
            exit()
else:
    print("Wrong input")
    exit()
num = int(num)
a = num

def simple(a):
    '''Проверка, простое ли число.'''
    if a % 2 == 0:
        return a == 2
    d = 3
    while d * d <= a and a % d != 0:
        d += 2
    rec = d * d > a
    return rec

rec = simple(a)
if rec == True:
    print(num)
    exit()

a = num
simple(a)
rec = simple(a)
while rec == False:
    a -= 1
    rec = simple(a)
    simple(a)
num_min = a

a = num
simple(a)
rec = simple(a)
while rec == False:
    a += 1
    rec = simple(a)
    simple(a)
num_max = a

if num - num_min <= num_max - num:
    print(num_min)

elif num - num_min > num_max - num:
    print(num_max)
